import {
    CreateDateColumn,
    UpdateDateColumn
} from "typeorm";
import {Expose} from "class-transformer";
import * as dayjs from "dayjs";
import {ApiProperty} from "@nestjs/swagger";

const transformer = {
    to: (value: Date) => (value),
    from: (value: Date) => (`${dayjs(value).format('YYYY-MM-DD HH:mm:ss')}`),
}

export class EntityBase {
    @ApiProperty({type: Date, description: '创建时间'})
    @CreateDateColumn({
        type: 'timestamp',
        transformer,
        nullable: false,
        comment: '创建时间'
    })
    @Expose()
    createAt: Date;

    @ApiProperty({type: Date, description: '更新时间'})
    @UpdateDateColumn({
        type: 'timestamp',
        transformer,
        nullable: false,
        comment: '更新时间'
    })
    @Expose()
    updateAt: Date;
}
